package com.fms.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.fms.model.Form9_sub;

public class Form9_subDAO {
	
	private SqlSessionFactory sqlSessionFactory; 
	
	public Form9_subDAO(){
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}
	

	/**
	 * Returns the list of all Form9_sub instances from the database.
	 * @return the list of all Form9_sub instances from the database.
	 */
	@SuppressWarnings("unchecked")
	public List<Form9_sub> selectAll(){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			List<Form9_sub> list = session.selectList("Form9_sub.getAll");
			return list;
		} finally {
			session.close();
		}
	}

	/**
	 * Returns a Form9_sub instance from the database.
	 * @param id primary key value used for lookup.
	 * @return A Form9_sub instance with a primary key value equals to pk. null if there is no matching row.
	 */
	public Form9_sub selectById(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			Form9_sub form9_sub = (Form9_sub) session.selectOne("Form9_sub.getBySubId",id);
			return form9_sub;
		} finally {
			session.close();
		}
	}

	/**
	 * Updates an instance of Form9_sub in the database.
	 * @param Form9_sub the instance to be updated.
	 */
	public void update(Form9_sub form9_sub){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.update("Form9_sub.update", form9_sub);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Insert an instance of Form9_sub into the database.
	 * @param Form9_sub the instance to be persisted.
	 */
	public void insert(Form9_sub form9_sub){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.insert("Form9_sub.insert", form9_sub);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Delete an instance of Form9_sub from the database.
	 * @param id primary key value of the instance to be deleted.
	 */
	public void delete(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.delete("Form9_sub.deleteBySubId", id);
			session.commit();
		} finally {
			session.close();
		}
	}
}
